package com.bms.controller.xybank;

import com.bms.common.response.ActivityResponse;
import com.bms.common.response.Result;
import com.bms.entity.Activity;
import com.bms.entity.Budget;
import com.bms.service.ActivityService;
import com.bms.utils.MyResult;
import com.bms.utils.MyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Description: 活动控制层
 * Author: jingcaiqi1225@gmail.com
 * Date: 2024/10/29 17:10
 */
@RestController
@RequestMapping("/activity")
public class ActivityController {

    @Autowired
    private ActivityService activityService;


    /**
     * 获取活动计数
     *
     * @return 活动计数
     */
    @GetMapping(value = "/getCount")
    public Result getCount() {
        Integer count = activityService.getCount();
        return Result.success(count);
    }

    /**
     * 添加新活动
     *
     * @param activity 新活动信息
     * @return 添加结果
     */
    @PostMapping("/addActivity")
    public Result addActivity(@RequestBody Activity activity) {
        return Result.success(activityService.addActivity(activity));
    }

    /**
     * 分页查询活动
     *
     * @param params 分页和搜索参数
     * @return 查询结果
     */
    @GetMapping(value = {"/queryActivitiesByPage", "reader/queryActivitiesByPage"})
    public Map<String, Object> queryActivitiesByPage(@RequestParam Map<String, Object> params) {
        MyUtils.parsePageParams(params);
        int count = activityService.getSearchCount(params);
        List<ActivityResponse> activities = activityService.searchActivitiesByPage(params);
        return MyResult.getListResultMap(0, "success", count, activities);
    }

    /**
     * 更新活动信息
     *
     * @param activity 更新的活动信息
     * @return 更新结果
     */
    @PutMapping(value = "/updateActivity")
    public Result updateActivity(@RequestBody Activity activity) {
        Integer count = activityService.updateActivity(activity);
        return Result.success(count);
    }

    /**
     * 更新活动状态
     *
     * @param activity 更新的活动状态
     * @return 更新结果
     */
    @PutMapping(value = "/updateStatus")
    public Result updateStatus(@RequestBody Activity activity) {
        Integer res = activityService.updateStatus(activity);
        return Result.success(res);
    }

    /**
     * 获取活动选择列表
     *
     * 该方法通过GET请求处理获取活动选择列表的请求它从activityService中获取活动列表，
     * 并将这些信息封装在一个Result对象中返回给客户端这个方法没有参数，
     * 也不产生任何副作用它只是从服务层获取信息并将其返回
     *
     * @return Result 包含活动列表的Result对象如果操作成功，返回的状态码将是成功状态
     */
    @GetMapping(value = "/getActivitiesSelectList")
    public Result getActivitiesSelectList(){
        List<Activity> list = activityService.getActivitiesSelectList();
        return Result.success(list);
    }
}
